<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="commentList" >
            <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="评论的用户名字" align="center" prop="commentName" />
      <el-table-column label="评价的内容" align="center" prop="commentInfo" />
      <el-table-column label="评论的图片" align="center" prop="commentImg" >
        <template slot-scope="scope">
            <el-image v-for="item in scope.row.commentImg? scope.row.commentImg.split(','):[]" 
                          style="width: 50px; height: 50px; margin-right: 5px"
                          :key="item"
                          :src="IMAGE_OSS_URL+'/'+item"
                          :preview-src-list="[...IMAGE_OSS_URL+item]"
                        > 
            </el-image> 

        </template>
         
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:comment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list ,remove } from "@/api/comment";
import { IMAGE_OSS_URL } from "@/config/index"

export default {
  name: "Comment",
  data() {
    return {
      // 遮罩层
      loading: true,
      IMAGE_OSS_URL,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单的评价表格数据
      commentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        customerId: null,
        goodsId: null,
        commentInfo: null,
        score: null,
        commentImg: null,
        commentName: null,
        status: null,
        extendInfo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "上线 1 下线0不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单的评价列表 */
    getList() {
      this.loading = true;
      list(this.queryParams.pageNum,this.queryParams.pageSize,{}).then(response => {
        this.commentList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        customerId: null,
        goodsId: null,
        commentInfo: null,
        score: null,
        commentImg: null,
        commentName: null,
        status: null,
        remark: null,
        extendInfo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
   
   
  
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除评价内容为==》：'+row.commentInfo).then(function() {
        return remove(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
